---@class GT.ui.model.sysMsgTip 系统提示
GT.ui.model.sysMsgTip = class()

sysMsgTip = OrderedTable()

---@class sysMsgTip_data 系统缓动UI提示
---@field prefix Str 文本
---@field text Str 文本






---@param data sysMsgTip_data
function GT.ui.model.sysMsgTip:ctor(data)
    self.ui = {}
    self.prefab = {}
    self.tick = {}

    self.prefab["系统提示"] = GT.ui.prefab.obj({
        module = "e0f5cef0-33a4-4b45-ac76-b75a9fa2a1ae",
        parent = "panel_2",
    })
    self.flushed = {}

    local p = self.prefab["系统提示"]

    self.ui["self"] = p:child(GT.ui.control.image, "系统提示")
    self.ui["前缀"] = p:child(GT.ui.control.label, "前缀")
    self.ui["内容"] = p:child(GT.ui.control.label, "内容")
    self.ui["self"].binding.opacity = 100
    self.ui["self"].binding.x = -350
    self.ui["self"].binding.y = 350
    self.ui["self"].binding.z_order = 999
    self.ui["前缀"].binding.text = data.prefix
    self.ui["内容"].binding.text = data.text
    self.uuid = uuid()

    for key, value in pairs(sysMsgTip) do
        local t2 = tween.new(0.1, value.ui['self'].binding, { y = value.y }, 'linear')
        tick.add(function(uuid)
            if t2:update(0.01) then
                tick.del(uuid)
            end
        end)
        value.y = value.y + value.ui['self'].h
    end
    local t1 = tween.new(0.3, self.ui['self'].binding, { x = 500, opacity = 100 }, 'outQuart')
    tick.add(function(uuid)
        if t1:update(0.03) then
            tick.del(uuid)
            local showT = tween.new(5, self.ui['self'].binding, { opacity = 0 }, 'linear')
            tick.add(function(uuid)
                if showT:update(0.01) then
                    tick.del(uuid)
                    self:del()
                end
            end)
        end
    end)
    sysMsgTip[self.uuid] = self
    self.y = self.ui['self'].y + self.ui['self'].h
end

function GT.ui.model.sysMsgTip:del()
    ---@type GT.ui.model.sysMsgTip
    local tip = sysMsgTip[self.uuid]
    tip.ui['self']:dtor()
    sysMsgTip[self.uuid] = nil
end

---转对象
---@param data sysMsgTip_data
function GT.ui.model.sysMsgTip.obj(data)
    workQueue:enqueue(function()
        new(GT.ui.model.sysMsgTip, data)
    end)
end

---转对象
---@param text
function GT.ui.model.sysMsgTip.obj2(text)
    workQueue:enqueue(function()
        new(GT.ui.model.sysMsgTip, { text = text, prefix = '系统' })
    end)
end
